﻿using AntdUI;
using PosClient.Model;
using PosClient.Service;
using PosClient.ViewModel;
using ReactiveUI;
using Splat;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PosClient.View
{
    public partial class ScanPayView : Window, IViewFor<ScanPayViewModel>
    {
        object IViewFor.ViewModel
        {
            get => ViewModel;
            set => ViewModel = (ScanPayViewModel)value;
        }
        public ScanPayViewModel ViewModel { get; set; }

        public ScanPayView(PayViewModel payViewModel)
        {
            InitializeComponent();
            InitBinding(payViewModel);
            InitData();
            InitEvent();
        }
        private void InitData()
        { 
            payRow1.Svg = DataUtil.PayIconList.TryGetValue(ViewModel.SelectPay.PayCode, out var svg) ? svg : DefaultIcon();
        }

        private void InitBinding(PayViewModel payViewModel)
        {
            ViewModel = new ScanPayViewModel();
            ViewModel.SelectPay = payViewModel.SelectPay;
            ViewModel.PayViewModel = payViewModel;
            this.WhenActivated(d =>
            {
                this.Bind(ViewModel,
                    vm => vm.SelectPay.PayName,
                    v => v.label_title.Text
                    ).DisposeWith(d);

                this.Events().Load
                    .Do(x => ActiveControl = input1)
                    .Subscribe()
                    .DisposeWith(d);

                this.Bind(ViewModel,
                    vm => vm.SelectPay.PayName,
                    v => v.payRow1.Text
                    ).DisposeWith(d);

            });
        }

        private void InitEvent()
        { 
            
        }

        private string DefaultIcon()
        {
            return "<svg t=\"1734423224094\" class=\"icon\" viewBox=\"0 0 1210 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"6860\" width=\"128\" height=\"128\"><path d=\"M568.847515 538.686061c-148.867879 0-268.474182-121.980121-268.474182-270.491152C300.373333 119.683879 422.632727 0.356848 568.847515 0.356848c148.852364 0 268.474182 121.980121 268.474182 267.838061 2.653091 148.51103-119.621818 270.506667-268.474182 270.506667z m0-501.201455c-127.596606 0-228.600242 103.424-228.600242 228.072727 0 127.286303 103.656727 230.710303 228.600242 230.710303 127.581091 0 228.600242-103.424 228.600243-230.710303 2.653091-124.648727-101.003636-228.072727-228.600243-228.072727z\" fill=\"#18b3d1\" p-id=\"6861\"></path><path d=\"M715.046788 114.377697L622.002424 273.501091h63.798303v47.740121h-79.747879v37.112243h79.747879v47.740121h-79.747879v66.296242h-74.426181v-66.296242h-85.054061v-47.740121h85.054061v-37.112243h-85.054061v-47.740121h69.104485L425.301333 114.362182h79.747879c34.552242 74.255515 58.476606 121.995636 66.451394 145.857939h2.653091c0-2.637576 2.668606-7.959273 5.321697-13.249939 2.668606-7.959273 13.296485-31.837091 34.552242-71.602424L640.620606 114.362182h74.426182zM21.255758 923.229091c-10.627879 0-21.255758-7.959273-21.255758-21.224727V610.304c2.653091-10.612364 10.627879-18.571636 21.255758-18.571636 10.643394 0 21.271273 7.959273 21.271272 21.209212v294.368969c0 7.959273-10.627879 15.918545-21.255757 15.918546z\" fill=\"#18b3d1\" p-id=\"6862\"></path><path d=\"M730.980848 838.361212l297.720243-111.383273c61.129697-23.862303 127.581091 7.959273 151.52097 68.949334l10.627878 23.877818-451.894303 161.76097c-82.385455 29.168485-170.108121 29.168485-255.177697 2.653091l-321.629091-114.036364V607.650909l63.798304-21.224727c71.773091-23.862303 146.199273-15.90303 217.956848 10.612363l366.824727 159.107879-69.104485 71.61794a103.330909 103.330909 0 0 1-36.615757 23.846788c-19.657697 7.338667-41.177212 7.912727-61.750303 0L478.487273 790.652121l198.019879 52.084364\" fill=\"#18b3d1\" p-id=\"6863\"></path><path d=\"M608.721455 1024c-42.542545 0-87.722667-7.959273-130.249697-21.209212l-324.297697-114.036364a19.952485 19.952485 0 0 1-13.296485-18.571636V607.650909c0-7.959273 5.321697-15.918545 13.296485-18.571636l63.798303-21.209212c71.773091-23.862303 148.852364-18.571636 231.253333 10.612363L816.050424 737.590303c5.321697 2.653091 10.627879 7.959273 10.627879 13.265455 0 5.290667 0 13.249939-5.306182 18.556121l-18.618182 18.571636 215.319273-79.561697c34.552242-13.265455 71.773091-13.265455 106.325333 2.637576 31.883636 15.918545 58.476606 42.433939 71.773091 76.924121l10.627879 23.862303c2.653091 5.306182 2.653091 10.612364 0 15.918546-2.653091 5.290667-5.321697 7.943758-10.627879 10.596848L744.261818 1000.137697C701.750303 1016.040727 656.554667 1024 608.721455 1024zM180.751515 856.932848l308.348121 108.730182c82.40097 26.515394 164.801939 23.862303 241.881212-2.653091l433.291637-153.817212-2.668606-5.306182c-10.627879-26.515394-29.230545-45.08703-53.154909-55.699393-23.924364-10.596848-50.501818-10.596848-74.426182-2.637576l-295.067152 111.383272a105.735758 105.735758 0 0 1-101.003636 13.24994l-164.801939-60.974546c-10.627879-2.668606-15.949576-15.934061-10.627879-26.530909 2.653091-10.612364 15.949576-15.918545 26.577454-10.612363l164.80194 60.99006c26.577455 10.612364 55.823515 2.653091 77.079272-18.556121l47.864243-50.393212-340.247273-148.51103c-74.441697-26.515394-140.877576-29.168485-204.675879-10.596849l-53.170424 15.90303v236.032zM871.377455 406.093576c5.306182 0 7.974788-2.637576 13.280969-5.290667l151.52097-119.342545c5.306182-2.653091 7.974788-10.612364 7.974788-15.918546 0-5.290667-2.668606-13.249939-7.974788-15.90303l-151.52097-114.036364c-7.974788-7.959273-21.255758-5.306182-26.577454 2.637576-5.321697 7.974788-5.321697 21.224727 2.653091 29.168485l130.249697 98.133333-130.249697 103.424c-7.974788 7.959273-10.627879 18.571636-2.653091 29.168485 2.653091 7.959273 7.974788 7.959273 13.296485 7.959273z\" fill=\"#18b3d1\" p-id=\"6864\"></path></svg>";

        }
    }
}
